<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class search_model extends CI_Model {

	public function index($input ,$per_page ,$uri ,$result_by ,$category_by)
	{
		$this->db->limit($per_page ,$uri);
		$this->db->order_by($result_by ,'desc');
		$this->db->like('vdo.vdo_name',$input['search']);
		$this->db->or_like('vdo.vdo_des',$input['search']);
		$this->db->or_like('vdo.vdo_tag',$input['search']);

		if($category_by != 'all')
		{			
		// 	$this->db->join('category','category.category_id = vdo.category_id','left');
			$this->db->having("vdo.category_id = $category_by"); 	
		}
		$this->db->having('vdo.vdo_status = 0');
		$this->db->where('vdo_thumb.thumb_choose',1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');
		$this->db->group_by("vdo.vdo_id"); 
		$query = $this->db->get('vdo');

		return $query->result_array();
	}

	public function count_index($input ,$result_by ,$category_by)
	{	
		
		$this->db->order_by($result_by ,'desc');
		$this->db->like('vdo.vdo_name',$input['search']);		
		$this->db->or_like('vdo.vdo_des',$input['search']);
		$this->db->or_like('vdo.vdo_tag',$input['search']);


		if($category_by != 'all')
		{			
		// 	$this->db->join('category','category.category_id = vdo.category_id','left');
			$this->db->having("vdo.category_id = $category_by"); 	
		}
		$this->db->having('vdo.vdo_status = 0');
		$this->db->where('vdo_thumb.thumb_choose',1);
		$this->db->join('vdo_thumb','vdo_thumb.vdo_id = vdo.vdo_id','left');
		$this->db->group_by("vdo.vdo_id"); 
		$query = $this->db->get('vdo');
		// echo $this->db->last_query();
		return $query->result_array();
	}

	


}